#include "observe.h"
#include <algorithm>
namespace observe {

void CObserved::add_observe(CObserveBase *observe)
{
    if(m_observes.end()==std::find(m_observes.begin(),m_observes.end(),observe)){
        m_observes.push_back(observe);
    }else{
        cout<<"already inside"<<endl;
    }
}

void CObserved::remove_observe(CObserveBase* observe)
{
    auto iter = std::find(m_observes.begin(),m_observes.end(),observe);
    if(iter == m_observes.end()){
        cout<<"not exist"<<endl;
    }else{
        m_observes.erase(iter);
    }
}

CObserved::~CObserved()
{
    for(auto ob:m_observes){
        delete ob;
    }
}

void CObserved::update()
{
    for(auto ob:m_observes){
        ob->update();
    }
}

}

